<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@include file="/commons/header.jsp" %>


<div style="margin-left:210px;margin-top:65px;padding:10px 5px 0 5px;">

    <div style="line-height:26px;height:26px;margin-bottom:10px;">
        <h1 style="float:left;font-size:26px;">应用信息</h1>

        <span class="layui-breadcrumb" style="float:right;font-size:12px;">
                <a href="#">首页</a> <a><cite>发布版本</cite> </a>
            </span>
    </div>

    <form class="layui-form" action="" style="margin-top:30px;">


        <div class="layui-form-item" style="vertical-align:central;">
            <div class="layui-inline" style="width:500px;">
                <label class="layui-form-label">应用包</label>
                <div class="layui-input-inline" style="width:300px;">
                    <button type="button" class="layui-btn" id="test1" style="margin-left:10px;">
                        <i class="layui-icon">&#xe67c;</i>上传APK
                    </button>

                </div>
                <a id="application" href="#" style="display: none;">下载APK</a>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">应用名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="appName" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="vertical-align:central;">
            <div class="layui-inline" style="width:500px;">
                <label class="layui-form-label" style="margin-top:20px;">应用图标</label>
                <div class="layui-input-inline" style="width:300px;">
                    <image id="appimage" width="70" height="70" src="../images/touxiang.jpg"
                           width="70" style="margin-left:15px;">
                        <button type="button" class="layui-btn" id="test2" style="margin-left:10px;">
                            <i class="layui-icon">&#xe67c;</i>上传图标
                        </button>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">版本号</label>
                <div class="layui-input-inline">
                    <input type="text" id="appVersion" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">更新内容</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" style="width:70%;" id="updateContent"></textarea>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="formDemo">发布新版本</button>

            </div>
        </div>

    </form>

    <br><br><br><br><br><br><br><br>


    <script src="${pageContext.request.contextPath}/lib/layui.all.js"/>
    <script src="${pageContext.request.contextPath}/lib/lay/modules/form.js"></script>


    <script>

        layui.use(['form', 'layedit', 'laydate', 'upload'], function () {
            var upload = layui.upload;
            var laydate = layui.laydate;

            //执行实例,上传
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                ,accept: "images",
                exts:"apk",
                 acceptMime: 'application/apk',
                url: '${pageContext.request.contextPath}/manager/upload?op=appLogo' //上传接口
                ,
                accept: "images",
                done: function (res) {
                    //上传完毕回调
                    $($("#application").css("display", "inline"))
                    $("#application").attr("href", res["src"]);

                    layer.msg("上传成功");
                },
                error: function () {
                    //请求异常回调
                    layer.msg("上传失败");
                }
            });

            //执行实例
            var uploadInst = upload.render({
                elem: '#test2' //绑定元素
                ,
                url: '${pageContext.request.contextPath}/manager/upload?op=appLogo' //上传接口
                , acceptMime: 'image/*',
                accept: "images",
                done: function (res) {
                    //上传完毕回调


                    $("#appimage").attr("src", res["src"]);

                    layer.msg("上传成功");
                },
                error: function () {
                    //请求异常回调
                    layer.msg("上传失败");
                }
            });

            var form = layui.form;

            //监听提交
            form.on('submit(formDemo)', function (data) {
                var appName = $("#appName").val();
                var appimage = $("#appimage").attr("src");
                var appVersion = $("#appVersion").val();
                var updateContent = $("#updateContent").val();
                var address = $("#application").attr("href");

                if(address=="#")
                {
                    layer.msg("请上传APK文件");
                    return;
                }


                $.post("${pageContext.request.contextPath}/manager/ManagerServlet?op=addApp", {
                    "appName": appName,
                    "appimage": appimage,
                    "appVersion": appVersion,
                    "content": updateContent,
                    "address":address
                }, function (datas) {

                    var $dom = $.parseJSON(datas);
                    layer.msg($dom["error"]);

                });


                return false;

            });
        });
    </script>
<%@include file="/commons/footer.jsp" %>